/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.Sku;
import com.yami.shop.bean.model.SkuStock;
import com.yami.shop.common.constants.CacheNames;
import com.yami.shop.dao.SkuStockMapper;
import com.yami.shop.service.SkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库存信息
 *
 * @author LGH
 * @date 2022-05-06 14:59:42
 */
@Service
public class SkuStockServiceImpl extends ServiceImpl<SkuStockMapper, SkuStock> implements SkuStockService {

    @Autowired
    private SkuStockMapper skuStockMapper;


    @Override
    public int updateSkuStocks(Long skuId, Integer changeStock) {
        return skuStockMapper.updateSkuStocks(skuId, changeStock);
    }

    @Override
    @Cacheable(cacheNames = CacheNames.LIST_SKU_STOCK_KEY, key = "#prodId")
    public List<SkuStock> listSkuStockByProdId(Long prodId) {
        return skuStockMapper.listByProdId(prodId);
    }

    @Override
    public int updateStocks(Sku sku) {
        return skuStockMapper.updateStocks(sku);
    }
}
